/**
 * Created by easezhi on 2015/2/6.
 */
function getChecked(selector){
    var rows = $(selector).datagrid('getChecked');
    if(rows.length > 0){
        return rows;
    }else {
        $.messager.alert('提示', '请选择目标数据', 'error');
        return false;
    }
}
function getCheckedOne(selector){
    var rows = getChecked(selector);
    if(rows){
        if(rows.length > 1){
            $.messager.alert('提示', '请只选择一条项目', 'error');
            return false;
        }else{
            return rows[0];
        }
    }else{
        return false;
    }
}
function showGrid(param){
    var option = {
        title:param.title || null,
        url:param.url,
        queryParams:param.queryParam || null,
        method:param.method || 'post',
        rownumbers: true,
        idField : param.idField || 'id',
        pagination : true,
        sortName : param.sortName || null,//默认排序的列
        sortOrder: param.sortOrder || 'asc',
        pageSize : 10,
        pageList : [ 10, 20, 40, 80 ],
        fitColumns : true,
        fit : true,
        checkOnSelect : false,
        selectOnCheck : true,
        striped: true,//条纹交替
        columns:param.columns,
        toolbar:param.toolbar || null
    };
    $(param.selector).datagrid(option);
}
function openIdTab(option){
    var slct = option.selector || '#center_tabs';
    var tabs = $(slct).tabs('tabs');
    var existing= false,x;
    for(x in tabs){
        if(tabs[x].attr('id') == option.id){
            existing = true;
            break;
        }
    }
    if(existing){//具有指定id的tab已经存在
        $(slct).tabs('select', Number(x));
    }else{
        $(slct).tabs('add',{
            id:option.id,
            title: option.title || 'New tab',
            href:option.href,
            selected: true,
            closable:true
        });

    }
}